/*
 * POSDist.java
 *
 * Created on April 8, 2007, 10:45 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package assistedpostagger;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

/**
 *
 * @author Paul Arezina
 */
public class POSDist {
    
    private HashMap<String, Integer> POSCount;
    private HashMap<String, Integer> POSPercent;
    private boolean percentsComputed;
    
    /** Creates a new instance of POSDist */
    
    public POSDist() {
        
        POSCount = new HashMap();
        POSPercent = new HashMap();
        percentsComputed = false;
        
    }
    
    public void addCount(String part, Integer count) {
        
        Integer totalCount = count;
        
        if (POSCount.containsKey(part)) {
            totalCount += POSCount.get(part);
        }
        
        POSCount.put(part, totalCount);
        
    }
    
    public Set<String> getParts() {
        
        return POSCount.keySet();
        
    }
    
    public void computePercents() {
        
        Integer totalWords = 0;
        Iterator<String> keyLoop;
        
        keyLoop = POSCount.keySet().iterator();
        
        while(keyLoop.hasNext()) {
            
            totalWords += POSCount.get(keyLoop.next());
            
        }
        
        keyLoop = POSCount.keySet().iterator();
        
        while(keyLoop.hasNext()) {
            
            String thisWord = keyLoop.next();
            Integer wordPercent = POSCount.get(thisWord) * 100 / totalWords;
            POSPercent.put(thisWord, wordPercent);
            
        }
        
        percentsComputed = true;
        
    }
    
    
    public Integer getPercent(String part) {
        
        if (!(percentsComputed)) {
            computePercents();
        }
        
        return POSPercent.get(part);
        
    }
    
    public int getSize() {
        
        return this.POSCount.keySet().size();        
        
    }
    
}
